<script language="javascript">setTimeout(function(){window.location.reload()}, 300000)</script>
<div id="search">
	<% form_for(@new_search) do |f| %>
	    Follow a New Trend: <%= f.text_field(:query, {:id => "query"}) %>&nbsp;
		<%= render("searches/example_search_link") %>
		<%= f.hidden_field(:is_saved) %>
		<input type="hidden" name="ref" value="searches">
	<% end %>
	<%= render("searches/example_searches") %>
</div>
<%= flash[:error] %>
<br/>
<table class="hticks">
	<tr>
		<td class="vtick"></td>
		<% i = 0; while i < CONF.saved_search_chunks_per_page && ts = @timespans[i] do %>
		<td class="htick" colspan="<%= CONF.saved_search_htick_interval %>">
			<%= ts.after_date.strftime("%b %e %H:%M") %>
		</td>
		<% i += CONF.saved_search_htick_interval %>
		<% end %>
	</tr>
</table>
<% @searches.each do |search| %>
<div class="search_query">
	[<%= link_to("x", unsave_search_path(search)) %>] <%= link_to(search.query, search_path(search)) %> &nbsp;
</div>
<table class="results">
	<tr>
		<% runs = search.runs_for_timespans(@timespans) %>
		<% max = runs.collect{|ts_id, sr| sr.num}.max || 0  %>
		<td class="vtick">
			<% (-((max / CONF.saved_search_vtick_interval).ceil+1)...0).each do |i| %>
				<div style="height: <%= CONF.saved_search_vtick_interval - 1 %>px"><%= -i * CONF.saved_search_vtick_interval %></div>
			<% end %>
		</td>
		<% @timespans.each do |ts| num = runs[ts.id].num rescue nil  %>
			<td class="rc <%= num ? "y" : "n" %>" onclick="window.location.href='<%= drilldown_search_path(search, :timespan_id => ts.id) %>'">
				<% if num %>
					<div style="height: <%= num %>px">&nbsp;</div>
				<% end %>
			</td>
		<% end %>
	</tr>
</table>
<% end %>
<%= will_paginate(@timespans) %>
